package AcWing周赛;

import java.util.Arrays;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: a
 * Date: 2022-10-08
 * Time: 19:03
 */
public class Demo72_2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        int sum = 0;
        for(int i = 0; i < n; i++){
            a[i] = scanner.nextInt();
            b[i] = scanner.nextInt();
            sum += a[i];
        }
        int[] c = new int[n];
        for(int i = 0; i < n; i++){
            c[i] = a[i] - b[i];
        }
        Arrays.sort(c);
        int k = 0;
        for(int i = n - 1; i >= 0; i--){
            if(sum <= m){
                System.out.println(k);
                return;
            }
            sum -= c[i];
            k++;
        }
        if(sum <= m){
            System.out.println(k);
        }else{
            System.out.println("-1");
        }
    }
}
